<?php

namespace App\Http\Controllers\Admin\HomeUsers;

use DB;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Admin\HomeUsers\Api\homeUsersApi;
use App\Model\HomeUsers;
use App\Model\Address;

/**
 * @author mais <[<380354618@qq.com>]>
 * [用于加载会员管理模块的视图]
 */
class homeUsersController extends Controller
{
	//加载会员管理->用户列表视图
    public function list(){

        $users = HomeUsers::paginate(10);

    	return view('Admin/HomeUsers/member-list', ['list'=>$users]);

    }

    //加载用户管理->用户添加视图
    public function add(){
    	return view('Admin/HomeUsers/member-add');
    }

    public function doadd(){

    	$mod = new homeUsersApi();

        $res = $mod->add($_POST);
    }

    public function chagepassword()
    {
        $mod = new homeUsersApi();

        $res = $mod->find('home_users', $_GET['id']);

        return view('Admin/HomeUsers/member-changepassword', ['list'=>$res]);
    }

    public function show()
    {

        //用户收货地址
        $address = [];
        
        $address = Address::where('uid', $_GET['id'])->get();

        //用户信息
        $res = HomeUsers::find($_GET['id']);

        return view('Admin/HomeUsers/member-show', ['list'=>$res], ['address'=>$address]);
    }

    public function edit()
    {
        $mod = new homeUsersApi();

        $res = $mod->find('home_users', $_GET['id']);

        return view('Admin/HomeUsers/member-edit', ['list'=>$res]);
    }

    public function find(Request $request)
    {
        // dd($request);
         $uname = $request->input('name');

        $uname = "%".$uname."%";

        $list = HomeUsers::where('username', 'like', $uname)->paginate(10);
        
        return view('Admin/HomeUsers/member-list', ['list'=>$list]);
    }
}
